<template>
  <div class="login-container">
    <el-form :model="ruleForm2" :rules="rules2"
             status-icon
             ref="ruleForm2"
             label-position="left"
             label-width="0px"
             class="demo-ruleForm login-page">
      <h3 class="title">摄像头登录</h3>
      <el-form-item prop="ip">
        <el-input type="text"
                  v-model="ruleForm2.ip"
                  auto-complete="off"
                  placeholder="摄像头IP"
        ></el-input>
      </el-form-item>
      <el-form-item prop="userName">
        <el-input type="text"
                  v-model="ruleForm2.userName"
                  auto-complete="off"
                  placeholder="摄像头账号"
        ></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input type="password"
                  v-model="ruleForm2.password"
                  auto-complete="off"
                  placeholder="密码"
        ></el-input>
      </el-form-item>
      <el-form-item prop="port">
        <el-input type="password"
                  v-model="ruleForm2.port"
                  auto-complete="off"
                  placeholder="端口"
        ></el-input>
      </el-form-item>
      <el-checkbox
        v-model="checked"
        class="rememberme"
      >记住密码</el-checkbox>
      <el-form-item style="width:100%;">
        <el-button type="primary" style="width:100%;" @click="handleSubmit" :loading="logining">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import {login} from "../../api/login"
    export default {
        name: "login",
      data(){
          return {
            logining: false,
            ruleForm2: {
              ip: "",
              userName:"",
              password: "",
              port: ""
            },
            rules2: {
              ip: [{required: true, message: '请填写摄像头IP地址', trigger: 'blur'}],
              userName: [{required: true, message: '请填写摄像头账号', trigger: 'blur'}],
              password: [{required: true, message: '请输入摄像头密码', trigger: 'blur'}],
              port: [{required: true, message: '请输入摄像头端口号', trigger: 'blur'}]
            },
            checked: false
          }
      },
      methods:{
        handleSubmit(event){
          this.$refs.ruleForm2.validate((valid) => {
            if(valid){
              login(this.ruleForm2).then(value => {
                console.log(value)
                if(value.data.code == 0){
                  this.$router.push({path: '/face'});
                }
                else{
                  this.$alert('登陆失败，请检查！', 'info', {
                    confirmButtonText: 'ok'
                  })
                }

              })
             /* this.logining = true;
              if(this.ruleForm2.username === 'admin' &&
                this.ruleForm2.password === '123456'){
                this.logining = false;
                sessionStorage.setItem('user', this.ruleForm2.username);
                this.$router.push({path: '/'});
              }else{
                this.logining = false;
                this.$alert('', 'info', {
                  confirmButtonText: 'ok'
                })
              }*/
            }else{
              console.log('error submit!');
              return false;
            }
          })
        }
      }
    }
</script>

<style scoped>
  .login-container {
    width: 100%;
    height: 100%;
  }
  .login-page {
    -webkit-border-radius: 5px;
    border-radius: 5px;
    margin: 180px auto;
    width: 350px;
    padding: 35px 35px 15px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
  }
  label.el-checkbox.rememberme {
    margin: 0px 0px 15px;
    text-align: left;
  }
</style>
